/*
 * Copyright 2002-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.beans.factory;

import java.lang.annotation.Annotation;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.core.ResolvableType;
import org.springframework.lang.Nullable;

/**
 * ListableBeanFactory实现了BeanFactory接口，
 * Listable意思是能列在单子上的，
 * ListableBeanFactory可以枚举它们的所有bean信息，
 * 而不用一个个通过bean的名称或类型一个个查找。
 * 如果容器是有层级的，比如实现了HierarchicalBeanFactory接口，
 * 返回值不考虑层级的信息，只读取当前容器定义的信息。
 *
 * @author Rod Johnson
 * @author Juergen Hoeller
 * @see HierarchicalBeanFactory
 * @see BeanFactoryUtils
 * @since 16 April 2001
 */
public interface ListableBeanFactory extends BeanFactory {

	/**
	 * 主要有判断是否有包含某个bean
	 *
	 * @see #containsBean
	 */
	boolean containsBeanDefinition(String beanName);

	/**
	 * 当前bean的总数,如果注册到容器中，但不是BeanDefinition的，不会统计在内。
	 */
	int getBeanDefinitionCount( );

	/**
	 * bean的名称数组。
	 */
	String[] getBeanDefinitionNames( );


	/**
	 * 根据条件，返回bean名称和bean的数组
	 */
	String[] getBeanNamesForType(ResolvableType type);


	String[] getBeanNamesForType(ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit);


	String[] getBeanNamesForType(@Nullable Class<?> type);


	String[] getBeanNamesForType(@Nullable Class<?> type, boolean includeNonSingletons, boolean allowEagerInit);


	<T> Map<String, T> getBeansOfType(@Nullable Class<T> type) throws BeansException;

	<T> Map<String, T> getBeansOfType(@Nullable Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)
			throws BeansException;


	String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);

	Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws BeansException;


	@Nullable
	<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
			throws NoSuchBeanDefinitionException;

}
